package cn.hinglo;

import cn.hinglo.baseservice.config.DbConfig;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import tk.mybatis.spring.annotation.MapperScan;

import javax.sql.DataSource;


/**
 * @createTime: 2018/11/15 9:30
 * @author: HingLo
 * @description: 服务层的启动类 * @EnableTransactionManagement 启用事物注解 * @EnableCaching 启用缓存注解
 * * @ServletComponentScan Servlet注解 * @SpringCloudApplication *
 * 定义了SpringCloud应用并包含了服务发现与服务容错保护2个注解 * @EnableFeignClients 启用Feign 客户端注解 *
 * ****************************************
 */
@EnableTransactionManagement
@EnableCaching
@ServletComponentScan
@MapperScan(value = {"cn.hinglo.*.mapper"}, annotationClass = Repository.class)
@SpringBootApplication
public class PermissionAdminApplication {

    // ************************JFinal 的ActiveRecord 启动**********************
    /**
     * 配置注入数据源
     */
    @Autowired
    private DataSource datasource;

    /***
     * 启动类
     *
     * @param args 启动参数
     */
    public static void main(String[] args) {
        SpringApplication.run(PermissionAdminApplication.class, args);
    }
    // ************************JFinal 的ActiveRecord 启动**********************

    /**
     * JFinal 的ActiveRecord 数据库依赖启动配置
     *
     * @return 返回配置对象
     */
    @Bean
    public DbConfig dbConfig() {
        ActiveRecordPlugin arp = new ActiveRecordPlugin(datasource);
        return new DbConfig(arp);
    }


}
